package info.erlbach_kirchberg.erzWoerterbuch;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.LinkedList;

import info.erlbach_kirchberg.erzWoerterbuch.ServerData.TermData;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TwoLineListItem;

public class TwoLineArrayAdapter extends ArrayAdapter<TermData> {
	private Context context;
	private TermData[] td;

	public TwoLineArrayAdapter(Context context, TermData[] td) {
		super(context,android.R.layout.simple_list_item_2,td);
		this.context = context;
		this.td=td;
	}
	
	
    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        TwoLineListItem row;            
        if(convertView == null){
            LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = (TwoLineListItem)inflater.inflate(android.R.layout.simple_list_item_2, null);                    
        }else{
            row = (TwoLineListItem)convertView;
        }
        TermData data = td[position];
        
        if (data != null) {
	        row.getText1().setText(data.term);
	        
	        //stringaufbereitung --> besser global in Termliste vor-verarbeiten
	        //String test = data.definition.split("\r\n\r\n*")[0];
	        //test = test.replaceAll("### ", "");
	
			row.getText2().setText(Html.fromHtml(data.translations));
        }
        
        return row;
        
    }
}
	

